package io.lkt.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import io.lkt.common.validator.ValidatorUtils;
import io.lkt.modules.sys.entity.TestUserEntity;
import io.lkt.modules.sys.service.TestUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2019-03-07 18:27:32
 */
@RestController
@RequestMapping("/sys/testuser")
public class TestUserController {
    @Autowired
    private TestUserService testUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:testuser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = testUserService.queryPage(params);
        System.out.println(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:testuser:info")
    public R info(@PathVariable("id") Long id){
        TestUserEntity testUser = testUserService.getById(id);

        return R.ok().put("testUser", testUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:testuser:save")
    public R save(@RequestBody TestUserEntity testUser){
        testUserService.save(testUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:testuser:update")
    public R update(@RequestBody TestUserEntity testUser){
        ValidatorUtils.validateEntity(testUser);
        testUserService.updateById(testUser);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:testuser:delete")
    public R delete(@RequestBody Long[] ids){
        testUserService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
